//
//  HSScoreViewModel.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/10/10.
//  Copyright © 2016年 赖虹宇. All rights reserved.
//

import UIKit



class HSScoreViewModel {
    
      //单一消息模型
    var scoreM : HSScoreModel 
    
    var isShowT: Bool = false {
        didSet {
            //教师评语富文本完成
            teachercomments = setupTeacherCommentsAtt(str: scoreM.es_comment ?? "")
        }
    }
    //教师评语富文本
    var teachercomments : NSAttributedString = NSAttributedString()
    //教师评语视图的高度
    var cellHight : CGFloat = 0
    
    init(model : HSScoreModel) {
         scoreM = model
        //教师评语富文本完成
       teachercomments = setupTeacherCommentsAtt(str: scoreM.es_comment ?? "")
    }
    
    fileprivate func setupTeacherCommentsAtt (str:String) -> NSAttributedString {
    if scoreM.es_teacherName == nil {
        return NSAttributedString()
    
        }
        var h: CGFloat = 90.5
        
        let detailComments = NSAttributedString(string: scoreM.es_comment ?? "", attributes: [NSForegroundColorAttributeName:UIColor().colorWithHex(0x99999),NSFontAttributeName:UIFont.systemFont(ofSize: 13)])
        let teaComments = NSMutableAttributedString(string: "教师评语 :", attributes: [NSForegroundColorAttributeName:UIColor().colorWithHex(0xd60a82),NSFontAttributeName:UIFont.systemFont(ofSize: 13)])
        
        teaComments.append(detailComments)
        //谁在前面就把谁变成可变的 才能用OC的方法
        
       
       
        let teaSize = CGSize(width: screenW-32, height: CGFloat(MAXFLOAT))
       //评语的高度
        let teaH = teaComments.boundingRect(with: teaSize, options: .usesLineFragmentOrigin, context: nil).size.height
        if isShowT {
            h += teaH + 20
        }
         //计算cell的高度
        cellHight = h
        return teaComments
        }
    
    
}
